package com.larry.phoenix;

import java.sql.*;
import java.util.Properties;

/**
 * @ProjectName hadoop
 * @Author larry
 * @Date 16:11 2021/12/10
 * @Description TODO
 **/
public class ThinkClientDemo {
    public static void main(String[] args) throws SQLException {
        String url = "jdbc:phoenix:hadoop102,hadoop103,hadoop104:2181";
        Properties props = new Properties();
        props.put("phoenix.schema.isNamespaceMappingEnabled","true");

        Connection connection = DriverManager.getConnection(url,props);

        //sql
        String sql = "select * from student";

        //预编译
        PreparedStatement preparedStatement = connection.prepareStatement(sql);

        //执行
        ResultSet resultSet = preparedStatement.executeQuery();
        while (resultSet.next()) {
            String id = resultSet.getString("id");
            String name = resultSet.getString("name");
            String addr = resultSet.getString("addr");

            System.out.println(id + "-" + name + "-" + addr);
        }

        resultSet.close();
        preparedStatement.close();
        connection.close();
    }
}
